<template>
  <view>
    <!-- 使用自定义的搜索组件 -->
    <view class="search-box">
      <my-search @click="gotoSearch"></my-search>
    </view>
    <!-- 通过uswiper生成代码 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
      <swiper-item v-for="(item,index) in swiperList" :key="index">
        <navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
          <image class="nav-img" :src="item.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <!-- 用emmet写view.nav-list>view.nav-item -->
    <view class="nav-list">
    	<view class="nav-item" v-for="(item,index) in navList" :key="index" @click="navClickHandler(item)">
        <image :src="item.image_src" mode=""></image>
      </view>
    </view>
    <view class="floor-list">
    	<view class="floor-item" v-for="(item,index) in floorList" :key="index">
    		<image class="floor-title" :src="item.floor_title.image_src"></image>
        <view class="floor-img-box">
          <navigator class="left-img-box"  :url="`/subpkg/goods_list/goods_list?${item.product_list[0].navigator_url.substr(item.product_list[0].navigator_url.indexOf('?')+1)}`">
            <image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
          </navigator>
          <navigator class="right-img-box" :url="`/subpkg/goods_list/goods_list?${item.product_list[0].navigator_url.substr(item.product_list[0].navigator_url.indexOf('?')+1)}`">
              <view class="right-img-item" v-for="(item2,index2) in item.product_list" :key="index2" v-if="index2!==0">
              	<image :src="item2.image_src" mode="widthFix" :style="{width:item2.image_width+'rpx'}"></image>
              </view>
          </navigator>
        </view>
    	</view>
    </view>
  </view>
</template>

<script>
  import tabbarBadge from '@/mixins/tabbar-badge.js'
  export default {    
    name: 'HomePage',
      mixins:[tabbarBadge],
    components:{
    },
    data() {
      return {
        swiperList:[] ,//轮播图的数据
        navList:[], //分类数据
        floorList:[], //楼层数据
      };
    },
    created(){
    },
    mounted(){
    },
    onLoad() {
      this.getSwiperList()
      this.getNavList()
      this.getFloorList()
    },
    methods:{
      // 跳转到分包中的搜索页面
      gotoSearch() {
        console.log('222')
        uni.navigateTo({
          url: '/subpkg/search/search'
        });
      },
      async getSwiperList(){
        let {data:{message,meta:{status}}} = await uni.$http.get('/api/public/v1/home/swiperdata')
        // let {data} = await uni.$http.get('/api/public/v1/home/swiperdata')
        // console.log(message)
        // console.log(status)
        if(status!==200) return uni.$showMsg()
        this.swiperList=message
      },
      async getNavList(){
         let {data:{message,meta:{status}}} = await uni.$http.get('/api/public/v1/home/catitems')
         // console.log(message)
         // console.log(status)
         if(status!==200) return uni.$showMsg()
         this.navList=message
      },
      navClickHandler(item){
        if(item.name==='分类'){
          uni.switchTab({
            url:'../cate/cate'
          })
        }
      },
      async getFloorList(){
         let {data:{message,meta:{status}}} = await uni.$http.get('/api/public/v1/home/floordata')
         console.log(message)
         // console.log(status)
         if(status!==200) return uni.$showMsg()
         this.floorList=message
      },
    }
  }
</script>

<style lang="scss">
swiper{
  height: 330rpx;
  .swiper-item,
  image{
    height: 100%;
    width: 100%;
  }
}
.nav-list {
  display: flex;
  justify-content: space-around;
  margin: 15px 0;
  }
  .nav-item{
    image{
      width: 128rpx;
      height: 140rpx;
    }
  }
  .floor-title{
    height: 60rpx;
    width: 100%;
    display: flex;
  }
.right-img-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}

.floor-img-box {
  display: flex;
  padding-left: 10rpx;
}
.search-box {
  // 设置定位效果为“吸顶”
  position: sticky;
  // 吸顶的“位置”
  top: 0;
  // 提高层级，防止被轮播图覆盖
  z-index: 999;
}
</style>
